package jmine.tec.test.matchers;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;

/**
 * @author lundberg
 * @param <T> compared type
 */
public class ReflectionBeanMatcher<T> extends BaseMatcher<T> {

    /**
     * @param <T> compared type
     * @param expected expected
     * @return matcher
     */
    public static <T> ReflectionBeanMatcher<T> matchesBean(T expected) {
        return new ReflectionBeanMatcher<T>(expected);
    }

    private final T expected;

    /**
     * Constructor
     * 
     * @param expected expected
     */
    public ReflectionBeanMatcher(T expected) {
        super();
        this.expected = expected;
    }

    /**
     * {@inheritDoc}
     */
    public void describeTo(Description description) {
        description.appendText(this.expected.toString());
    }

    /**
     * {@inheritDoc}
     */
    public boolean matches(Object actual) {
        return EqualsBuilder.reflectionEquals(this.expected, actual);
    }
}